/*
 * @Description: 电子文件级列表
 * @Author: Zzt
 * @Date: 2022-12-28 11:43:11
 * @LastEditTime: 2023-01-10 21:37:43
 */
import { isNullObj } from '@/utils';
import { Button, Table } from 'antd';
import { ColumnsType } from 'antd/es/table';
import { useEffect, useState } from 'react';
import { useReceiveAndSendCollectionContext } from '../../contexts/ReceiveAndSendCollectionContext';
const columns: ColumnsType = [
  { title: '序号', key: 'id', dataIndex: 'id', align: 'center' },
  { title: '名称', key: 'name', dataIndex: 'name', align: 'center' },
  { title: '大小', key: 'size', dataIndex: 'size', align: 'center' },
  { title: '格式', key: 'format', dataIndex: 'format', align: 'center' },
  {
    title: '操作',
    key: 'action',
    align: 'center',
    render: (_: any) => <Button type="link">原文预览</Button>
  }
];
const ElectronicFileList = () => {
  const { electronicList, setSelectKey, selectItems } = useReceiveAndSendCollectionContext();

  const [total, setTotal] = useState(0);
  const [listQuery, setListQuery] = useState({
    pageNo: 1,
    pageSize: 10,
    param: {}
  });
  useEffect(() => {
    if (listQuery && !isNullObj(listQuery.param)) {
      // setLoading(true);
      // getBusinessList(listQuery)
      //   .then((res: any) => {
      //     setTotal(res?.totalCount);
      //     setTimeout(() => {}, 2000);
      //   })
      //   .finally(() => {
      //     setLoading(false);
      //   });
    }
  }, [listQuery]);

  /**
   * @description 切换页码触发
   * @param {number} page 页码
   * @param {number} pageSize 每页条目数
   */
  const pageChange = (page: number, pageSize: number) => {
    setListQuery((state) => ({
      ...state,
      pageNo: page,
      pageSize
    }));
  };
  /**
   * @description : 表格选项相关设置
   * @param {number} selectedRowKeys 选择的项目的KEY
   */
  const onSelectChange = (selectedRowKeys: number[]) => {
    setSelectKey(selectedRowKeys);
    console.log('elKeys', selectedRowKeys);
    // setSelectKey(selectedRowKeys);
  };
  /**
   * @description:  表格多选配置
   */
  const rowSelection = {
    selectItems,
    onChange: onSelectChange
  };
  return (
    <>
      <Table
        columns={columns}
        dataSource={electronicList}
        size="small"
        bordered
        scroll={{ y: '300px' }}
        rowSelection={rowSelection}
        rowKey="id"
        pagination={{
          current: listQuery.pageNo,
          pageSize: listQuery.pageSize,
          total,
          onChange: pageChange,
          showTotal: (total) => `共 ${total} 条`
        }}
      ></Table>
    </>
  );
};
export default ElectronicFileList;
